import torch.nn.functional as F
# new score
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity

def calculate_score(generated_report, correct_report):
    vectorizer = TfidfVectorizer()
    reports = [generated_report, correct_report]
    tfidf_matrix = vectorizer.fit_transform(reports)
    similarity_score = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:2])[0][0]
    return similarity_score


generated_report = "The following is a medical report based on an image: The heart size and pulmonary vascularity appear within normal limits. Lungs are free of focal airspace disease. No pleural effusion or pneumothorax is seen."
correct_report =  "The heart size and pulmonary vascularity appear within normal limits. The lungs are free of focal airspace disease. No pleural effusion or pneumothorax is seen."
res = calculate_score(generated_report, correct_report)
print(res)